package com.fh.shop.admin.controller.book;

import com.fh.shop.admin.common.ServerResponse;
import com.fh.shop.admin.po.book.Book;
import com.fh.shop.admin.biz.book.IBookService;
import com.fh.shop.admin.common.DataTableResult;
import com.fh.shop.admin.param.book.BookQueryParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
@RequestMapping("/book")
public class BookController {
    @Resource(name = "bookService")
    private IBookService bookService;

    @RequestMapping(value = "toIndex",method = RequestMethod.GET)
    public String toIndex(){
        return "book/index";
    }

    @GetMapping("toAdd")
    public String toAdd(){
        return "book/add";
    }
    @GetMapping("toUpdate")
    public String toUpdate(){
        return "book/update";
    }

    @RequestMapping(value = "add",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse add(Book book){
        return bookService.addBook(book);
    }

    @PostMapping("/list")
    @ResponseBody
    public DataTableResult list(BookQueryParam bookQueryParam){
        return bookService.findBookList(bookQueryParam);
    }

    @PostMapping("findBook")
    @ResponseBody
    public ServerResponse findBook(Long id){
        return bookService.findBook(id);
    }

    @PostMapping("update")
    @ResponseBody
    public ServerResponse updateBook(Book book){
        return bookService.updateBook(book);
    }

    @PostMapping("delete")
    @ResponseBody
    public ServerResponse deleteBook(Long id){
        return bookService.deleteBook(id);
    }

    @PostMapping("deleteBatch")
    @ResponseBody
    public ServerResponse deleteBatchBook(String ids){
        return bookService.deleteBatchBook(ids);
    }

}
